Repository navigation
fix(state): keep a failing flock's errno under a timeout - #15
Merged
Merged
Conversation
fgetxattr was not retried on EINTR, so a signal refused the replacement. atomicWrite also leaked the temporary path, the step names and the spare ACL read. Tests cover both under std.testing.allocator.
copyTo renames the new bytes into place, so a full disk or a file-size limit leaves an existing file unchanged. appendLine rolls a short write back to the size before it, so the line list does not gain a partial line.
lockExclusive reads its deadline from the monotonic clock, so a signal that cuts a sleep short does not expire the wait. RootLock refuses a gate or sidecar that is not a regular file of this user with one link.
decodeCache and key comparison read past a string that ended on a backslash. They now return an encoding error, and the bytes allocated before that error are freed.
The list was abandoned on the error path, and the slice it returned was not the whole allocation, so a caller could not free it.
The archive is written under a temporary name, synced and renamed. A crash or a short write no longer leaves a partial name.gz that a later run skips.
groupAlive treated EINTR from getdents as "nobody is alive", so waitGroupGone could return while the group was still running.
COMPAT.md said errno 134 was the unnamed hardware-error text. On x86_64 that text is errno 133, HWPOISON, which Zig names; 134 is unnamed, as glibc prints it. The module summary matches the copy and the lock gate.
A caller started with fd 0, 1 or 2 closed gets /dev/null at that number. With fd 1 closed the child's stderr ends up in the captured stdout; with fd 0 or 2 closed the child loses that stream at exec. Each test forks, closes the descriptor and checks what the child sees. They fail until childExec is fixed.
…reams When the caller started with fd 0, 1 or 2 closed, /dev/null or a pipe took that number, and childExec's dup2 sequence either clobbered it (fd 1: the child's stderr went to the captured stdout) or made a no-op dup2 onto itself that kept close-on-exec (fd 0 or 2: the child started with that stream closed). Sources below 3 now move above 2 before the dup2s, as Python's _posixsubprocess does.
With SIGCHLD set to SIG_IGN the kernel reaps the child itself and wait4 fails with ECHILD. reap reports that as a kill by signal 9, so a child that exited 3 reads as SIGKILLed. The test expects error.NoChild and fails until reap returns the wait4 error.
reap turned any wait4 failure into a kill by signal 9. With SIGCHLD ignored the kernel reaps the child and wait4 fails with ECHILD, so run reported a SIGKILL for a child that exited normally. reap now returns the wait4 error through sys.call, run returns error.NoChild with sys.last_errno set, and run's doc says not to ignore SIGCHLD. The error paths still reap and keep their own error.
decodeCache("abc\\") and decodeWire("\\u12") index past the string and
panic, as does a key lookup on a key that ends in a backslash. The
decoders also take "\\u+123" (parseInt allows a sign) and read
"\\x0041" as a \u escape. The test expects error.Encoding under
std.testing.allocator, so nothing allocated before the error may leak.
codePoints read raw[i + 1] and the four \u digits without a bounds check, so a string ending in a backslash or a short \u escape panicked. It also handed any unknown escape to the \u branch and parsed the digits with parseInt, which accepts a sign. Escapes are now checked: a cut-off, unknown or non-hex escape is error.Encoding. keyEql gets the same bounds check. The decoders free their scratch and partial output on error, and return exact-length slices.
json.loads keeps 18446744073709551616 as an exact int. toPy falls back to parseFloat when parseInt overflows, so it becomes the float 18446744073709552000 and dumps writes it back as 1.8446744073709552e+19. The test expects an error, and checks that the i64 bounds and float-shaped numbers still read as before.
toPy tried parseInt and fell back to parseFloat on any failure, so an integer that overflows i64 came back as a float and changed type and digits. The JSON text's shape now decides: no fraction or exponent is an int, and one that does not fit is error.Encoding, which toPy already returns for a value it cannot represent. The error set is unchanged.
The depth check runs on every value at depth > 32. An empty container at depth 32 has no value inside it to check, so 33 nested empty arrays parse while 33 arrays around a scalar do not. The test pins one limit for both: 32 nested arrays or objects. It fails until the check runs on entering a container.
The depth check ran at the top of every value, so an empty container at depth 32 passed and the limit was 33 for empty containers but 32 around a scalar. It now runs on entering an array or object: at most 32 nested containers, now the public json.max_depth, documented at parse. The module doc still described one guard's JSON. It now names what the module holds: the parser, the cache and wire codecs, toPy, and dumps.
copyTo says it copies an open file as cp(1) does, but copyFd read from the descriptor's offset and left it at the end. A caller that read the first line got a copy without it. The test reads a header first, then expects the whole file in the copy and the offset where the read left it.
copyTo's doc promises a cp(1) copy of an open file, but copyFd read from the current offset and left it at the end of the file. copyFd now reads with pread from byte 0, so the copy is whole and the caller's offset is left alone. eb-keep-logs, the one caller, rewinds the source after the copy, which now does nothing; its tests pass against this change.
replaceContents copies system.posix_acl_access and system.nfs4_acl only, so a file on GPFS loses its native system.gpfs_nfs4_acl, which atomic copies. copyAcls now runs through a comptime type of xattr calls, which changes no behaviour, so the test can emulate each model as atomic_test does. It expects the most native form present to be copied, and only that one, and fails on the GPFS-only model.
copyAcls knew system.posix_acl_access and system.nfs4_acl but not system.gpfs_nfs4_acl, so replacing a file on GPFS dropped its native ACL, and it set every form it found where atomic sets the most native one. fsx.acl_attributes is now the one list of forms, most native first, and atomic aliases it. copyAcls copies the first form present. GPFS answers EINVAL for an NFSv4 form of a file whose ACL is POSIX; that EINVAL is skipped when a later form can be copied and refused otherwise, as in atomic.
atomic formats an ACL read failure with its own six-entry errno table and falls back to the errno's tag name. An ESTALE read then prints "[Errno 116] STALE" where sys prints "[Errno 116] Stale file handle", as Python does. The test fails every ACL read with ESTALE and expects sys's text.
readAllAcls kept a six-entry errno table of its own and printed any other errno by its tag name. sys.describeErrno already gives Python's "[Errno N] text" for every errno Linux names, so the table goes and both refusals use it.
…sage atomicWrite allocates the temporary path, the step names, every ACL it reads (the spare read of each double read included) and the inner refusal it wraps from the caller's allocator and frees none of them, which only an arena hides. The test runs a replacement, a metadata_from copy, an injected failure and a refusal under every ACL model with std.testing.allocator, freeing only why.msg.
Every ACL read is now freed when it is done with, the spare read of readAcls's double read included, and atomicWrite frees the temporary path, the step names, the metadata it read and the inner refusals it wraps, with errdefer on the paths that hand memory back. What is left is the caller's: a refusal's why.msg, freed by the new Why.deinit, which leaves alone the static text used when formatting the message runs out of memory, and the ACLs readAcls and readMetadata return, freed by Acls.deinit and Metadata.deinit.
The Ops doc said tests replace the calls under builtin.is_test only, but replaceable is also true in a tool's test artifact built with -Dtest-ops, where eb-staged-rebuild replaces them. The doc now says so, in the words Faults and state.LockOps use.
Without a timeout lockExclusive goes through sys.call, so a failing flock is its sys.Error and sys.last_errno names the errno. With one, every failure other than EAGAIN or EINTR becomes error.Unexpected and the errno is lost. The test locks a bad descriptor with no timeout, a zero one and a short one, and expects EBADF's error and text each time.
The polling loop turned every errno but EAGAIN and EINTR into error.Unexpected. It now maps the result with mapped(), as the record lock does, so the caller gets the sys.Error and sys.last_errno its errno, the same as without a timeout.
HaoZeke
force-pushed
the
fix/lock-errno
branch
from
November 16, 2026 08:16
f5b7ed1 to
ab17da1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
state.lockExclusivewith a timeout now returns a failing flock's own error, with its errno insys.last_errno, as it does without one.error.Unexpected, so the errno was lost.mapped(), as the record lock does, so the caller gets thesys.Errorandsys.last_errnoof that errno.Conflicts with #3 (fix/safety) in
src/state.zig; whichever lands second needs a rebase.The branch has a CHANGELOG Unreleased entry.